/*
 * Created by SharpDevelop.
 * User: michaelo
 * Date: 18/05/2005
 * Time: 19:18
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using Orz.LogManager.Config;


namespace Orz.LogManager
{
	/// <summary>
	/// Description of EditLogFile.
	/// </summary>
	public class EditLogFile : System.Windows.Forms.Form
	{
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Button cmdOK;
		private System.Windows.Forms.RadioButton optTelnet;
		private System.Windows.Forms.Button cmdNewMatch;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button cmdMatchUp;
		private System.Windows.Forms.RadioButton optLocal;
		private System.Windows.Forms.RadioButton optSSH;
		private System.Windows.Forms.ListView lvwAutoLogins;
		private System.Windows.Forms.Button cmdCancel;
		private System.Windows.Forms.TextBox txtHost;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button cmdAutoLoginDelete;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ColumnHeader colSend;
		private System.Windows.Forms.Button cmdAutoLoginNew;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.ListView lvwMatches;
		private System.Windows.Forms.Label lblUsername;
		private System.Windows.Forms.Button cmdAutoLoginUp;
		private System.Windows.Forms.ColumnHeader colReplace;
		private System.Windows.Forms.Label lblPassword;
		private System.Windows.Forms.Button cmdDeleteMatch;
		private System.Windows.Forms.ColumnHeader colColour;
		private System.Windows.Forms.Button cmdAutoLoginEdit;
		private System.Windows.Forms.TextBox txtLocalPath;
		private System.Windows.Forms.Button cmdEditMatch;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.GroupBox grpLocal;
		private System.Windows.Forms.TextBox txtTelnetPath;
		private System.Windows.Forms.Button cmdMatchDown;
		private System.Windows.Forms.Label lblUsernameAndPassword;
		private System.Windows.Forms.TextBox txtDisplayName;
		private System.Windows.Forms.ColumnHeader colMatch;
		private System.Windows.Forms.Button cmdImport;
		private System.Windows.Forms.ColumnHeader colWaitFor;
		private System.Windows.Forms.Button cmdAutoLoginDown;
		private System.Windows.Forms.Button cmdLocalBrowse;
		private System.Windows.Forms.TextBox txtUsername;
		private System.Windows.Forms.GroupBox grpTelnet;
		private System.Windows.Forms.TextBox txtTailCommand;
		private System.Windows.Forms.PictureBox picPassword;
		
		
		
		private logsetLogfile original_i;
		private logsetLogfile working_i;
		private bool bWasCancelled_i;
		
		private HelpForm help_i;
		
		private const int IMG_CLEARTEXT = 0;
		private const int IMG_ENCRYPTED = 1;
		
		
		
		public EditLogFile (logsetLogfile file_p)
		{
			InitializeComponent();
			
			original_i = file_p;
			
			// Make a backup of the working set before we start
			working_i = LogsetLoader.CloneLogfile (original_i);
			
			help_i = new HelpForm (this);
			
			PopulateFields();		
		}
		
		
		
		
		public bool WasCancelled
		{
			get { return bWasCancelled_i; }
		}
		
		
		
		
		private void PopulateFields ()
		{			
			lvwAutoLogins.Items.Clear();
			lvwMatches.Items.Clear();
			
			txtDisplayName.Text = working_i.name;
			
			if (LogsetLoader.isSSH (working_i))
			{
				optSSH.Checked = true;
			}
			else if (LogsetLoader.isTelnet (working_i))
			{
				optTelnet.Checked = true;
			}
			else
			{
				optLocal.Checked = true;
			}
				
			
			txtLocalPath.Text = working_i.path;
			
			txtTelnetPath.Text = working_i.path;
			txtHost.Text = working_i.telnetHost;
			txtTailCommand.Text = working_i.telnetCommand;
			txtUsername.Text = working_i.sshUsername;
			PopulateAutoLoginList();			
			PopulateMatchesList();			
		}
		
		
		
		
		private void PopulateAutoLoginList()
		{
			lvwAutoLogins.Items.Clear();
			
			IEnumerator e = working_i.autoLogin.GetEnumerator();
			
			while (e.MoveNext())
			{
				
				logsetLogfileAutoLogin al = (logsetLogfileAutoLogin) e.Current;
				
				int iImageIndex = al.send.encrypted ? IMG_ENCRYPTED : IMG_CLEARTEXT;
				
				ListViewItem item = lvwAutoLogins.Items.Add(al.pattern, iImageIndex);
				
				if (al.send.encrypted)
				{
					item.SubItems.Add ("(encrypted)");
				}
				else
				{
					item.SubItems.Add(al.send.Value);
				}
			}
			
			if (lvwAutoLogins.Items.Count > 0)
			{
				lvwAutoLogins.SelectedItems.Clear();
				lvwAutoLogins.Items[0].Selected = true;				
			}
			
			UpdateButtons();
		}
		
		
		private void PopulateMatchesList()
		{
			lvwMatches.Items.Clear();
			
			IEnumerator e = working_i.match.GetEnumerator();
			
			while (e.MoveNext())
			{
				logsetLogfileMatch match = (logsetLogfileMatch) e.Current;
				
				ListViewItem item = lvwMatches.Items.Add(match.pattern);				
				item.SubItems.Add (FormatOptionalString(match.replacement));
				item.SubItems.Add (FormatOptionalString(match.colour));				
			}
			
			if (lvwMatches.Items.Count > 0)
			{
				lvwMatches.SelectedItems.Clear();
				lvwMatches.Items[0].Selected = true;				
			}
			
			UpdateButtons();
		}
		
		
		private void UpdateButtons ()
		{
			bool areMatches = (lvwMatches.Items.Count > 0);
			cmdEditMatch.Enabled = areMatches;
			cmdDeleteMatch.Enabled = areMatches;
			cmdMatchUp.Enabled = areMatches;
			cmdMatchDown.Enabled = areMatches;
			
			bool areAutoLogins = (lvwAutoLogins.Items.Count > 0);
			cmdAutoLoginEdit.Enabled = areAutoLogins;
			cmdAutoLoginDelete.Enabled = areAutoLogins;
			cmdAutoLoginUp.Enabled = areAutoLogins;
			cmdAutoLoginDown.Enabled = areAutoLogins;			
		}
		
		
		private string FormatOptionalString (string s)
		{
			if (null == s) 
			{
				return "-none-";
			}
			else
			{
				return s;
			}
		}
		
		
		private void ShowOrHideFrames()
		{
			bool isRemoteFile = optTelnet.Checked  ||  optSSH.Checked;
			
			
			if (isRemoteFile)
			{
				grpTelnet.Text = optSSH.Checked ? "SSH settings" : "Telnet settings";
					
				this.txtUsername.Visible = optSSH.Checked;
				this.lblUsername.Visible = optSSH.Checked;
				this.picPassword.Visible = optSSH.Checked;
				this.lblPassword.Visible = optSSH.Checked;
				this.lblUsernameAndPassword.Visible = ! optSSH.Checked;
			}
			
			grpLocal.Visible = ! isRemoteFile;
			grpTelnet.Visible = isRemoteFile;
		}
		
		
		
		private bool DoSave()
		{
			string sPath = optLocal.Checked ? txtLocalPath.Text : txtTelnetPath.Text;
			
			if (0 == sPath.Length)
			{
				MessageBox.Show ("You must enter a path for the file.", this.Text);
				return false;
			}
			
			
			// Make sure the logfile has a name			
			if (0 == txtDisplayName.Text.Length)
			{
				txtDisplayName.Text = GetFileNameFromPath(sPath);					
			}
			
			// Check for remote host if necessary
			if ((optTelnet.Checked  ||  optSSH.Checked)  &&  0 == txtHost.Text.Length)
			{
				MessageBox.Show ("You must enter a remote host for a telnet or SSH file.", this.Text);
				return false;
			}
			
			// Check for remote command if necessary
			if ((optTelnet.Checked  ||  optSSH.Checked)  &&  0 == txtTailCommand.Text.Length)
			{
				MessageBox.Show ("You must enter a tail command for a telnet or SSH file.", this.Text);
				return false;
			}
			
			// Check for SSH username
			if (optSSH.Checked  &&  0 == txtUsername.Text.Length)
			{
				MessageBox.Show ("You must enter username for an SSH file.", this.Text);
				return false;
			}
			
			
			// Copy the values across to the working version
			original_i.name = txtDisplayName.Text;
			original_i.path = sPath;
			original_i.match = working_i.match;
			
			if (optSSH.Checked)
			{
				original_i.telnetProtocol = protocolType.ssh;
				original_i.sshUsername = txtUsername.Text;
				original_i.telnetHost = txtHost.Text;
				original_i.telnetCommand = txtTailCommand.Text;								
				original_i.autoLogin = working_i.autoLogin;
			}
			else if (optTelnet.Checked)
			{
				original_i.telnetProtocol = protocolType.telnet;
				original_i.sshUsername = null;
				original_i.telnetHost = txtHost.Text;
				original_i.telnetCommand = txtTailCommand.Text;				
				original_i.autoLogin = working_i.autoLogin;
			}
			else
			{
				original_i.sshUsername = null;
				original_i.telnetHost = null;
				original_i.telnetCommand = null;
				original_i.autoLogin = new logsetLogfileAutoLogin[0];
			}
			
			return true;
		}
		
		
		private string GetFileNameFromPath (string sPath_p)
		{
			if (sPath_p.IndexOf("/") >= 0)
			{
				string[] vParts = sPath_p.Split('/');
				return vParts[vParts.Length-1];
			}
			else if (sPath_p.IndexOf("\\") >= 0)
			{
				string[] vParts = sPath_p.Split('\\');
				return vParts[vParts.Length-1];
			}
			else
			{
				return sPath_p;
			}
		}
		
		
		void LvwMatchesSelectedIndexChanged(object sender, System.EventArgs e)
		{
			
		}
		
		void OptLocalCheckedChanged(object sender, System.EventArgs e)
		{
			ShowOrHideFrames();
		}
		
		void OptTelnetCheckedChanged(object sender, System.EventArgs e)
		{
			ShowOrHideFrames();
		}
		
		void OptSSHCheckedChanged(object sender, System.EventArgs e)
		{
			ShowOrHideFrames();
		}
		
		void CmdOKClick(object sender, System.EventArgs e)
		{
			if (DoSave())
			{
				bWasCancelled_i = false;
				this.Close();
			}
		}
		
		void CmdCancelClick(object sender, System.EventArgs e)
		{
			bWasCancelled_i = true;
			this.Close();
		}
		
		
		
		
		void GrpTelnetEnter(object sender, System.EventArgs e)
		{
			
		}
		
		void CmdNewMatchClick(object sender, System.EventArgs e)
		{
			logsetLogfileMatch match = new logsetLogfileMatch();
			
			MatchForm f = new MatchForm(match);
			f.ShowDialog();
			
			if (! f.WasCancelled)
			{
				logsetLogfileMatch[] origArray = working_i.match;
				
				logsetLogfileMatch[] newArray = new logsetLogfileMatch[origArray.Length+1];
				
				for (int i=0; i<origArray.Length; i++)
				{
					newArray[i] = origArray[i];
				}
				     
				newArray[newArray.Length-1] = match;
				
				working_i.match = newArray;
			}
			
			PopulateMatchesList();
		}
		
		void CmdEditMatchClick(object sender, System.EventArgs e)
		{
			if (0 == lvwMatches.Items.Count  ||  0 == lvwMatches.SelectedIndices.Count) return;
			
			int iIndex = lvwMatches.SelectedIndices[0];
			logsetLogfileMatch match = working_i.match[iIndex];			
			
			MatchForm f = new MatchForm(match);
			f.ShowDialog();
			
			PopulateMatchesList();
		}
		
		
		
		void LvwMatchesDoubleClick(object sender, System.EventArgs e)
		{
			CmdEditMatchClick(sender, e);
		}
		
		
		
		void CmdDeleteMatchClick(object sender, System.EventArgs e)
		{
			if (0 == lvwMatches.Items.Count  ||  0 == lvwMatches.SelectedIndices.Count) return;
			
			int iIndex = lvwMatches.SelectedIndices[0];
			logsetLogfileMatch match = working_i.match[iIndex];
			
			if (DialogResult.Yes == MessageBox.Show ("Are you sure you want to remove this search for '" + match.pattern + "'?", this.Text, MessageBoxButtons.YesNo))
			{				
				logsetLogfileMatch[] origArray = working_i.match;
					
				logsetLogfileMatch[] newArray = new logsetLogfileMatch[origArray.Length-1];
				
				for (int i=0; i<origArray.Length; i++)
				{					
					if (i < iIndex)
					{
						newArray[i] = origArray[i];
					}
					else if (i > iIndex)
					{
						newArray[i-1] = origArray[i];
					}
				}
								
				working_i.match = newArray;
				
				PopulateMatchesList();
			}
		}
		
		void CmdMatchUpClick(object sender, System.EventArgs e)
		{
			if (lvwMatches.Items.Count < 2  ||  
			    0 == lvwMatches.SelectedIndices.Count) return;
			
			int iIndex = lvwMatches.SelectedIndices[0];
			if (0 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileMatch tmp = working_i.match[iIndex-1];			
			working_i.match[iIndex-1] = working_i.match[iIndex];
			working_i.match[iIndex] = tmp;
			
			PopulateMatchesList();
			
			lvwMatches.Items[iIndex-1].Selected = true;					
		}
		
		void CmdMatchDownClick(object sender, System.EventArgs e)
		{
			if (lvwMatches.Items.Count < 2  ||  0 == lvwMatches.SelectedIndices.Count) return;
			
			int iIndex = lvwMatches.SelectedIndices[0];
			if (lvwMatches.Items.Count-1 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileMatch tmp = working_i.match[iIndex+1];
			working_i.match[iIndex+1] = working_i.match[iIndex];
			working_i.match[iIndex] = tmp;
			
			PopulateMatchesList();
			
			lvwMatches.Items[iIndex+1].Selected = true;	
		}
		
		
		
		
		
		
		void CmdAutoLoginUpClick(object sender, System.EventArgs e)
		{
			if (lvwAutoLogins.Items.Count < 2  ||  
			    0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			int iIndex = lvwAutoLogins.SelectedIndices[0];
			if (0 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileAutoLogin tmp = working_i.autoLogin[iIndex-1];			
			working_i.autoLogin[iIndex-1] = working_i.autoLogin[iIndex];
			working_i.autoLogin[iIndex] = tmp;
			
			PopulateAutoLoginList();
			
			lvwAutoLogins.Items[iIndex-1].Selected = true;	
		}
		
		void CmdAutoLoginDownClick(object sender, System.EventArgs e)
		{
			if (lvwAutoLogins.Items.Count < 2  ||  0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			int iIndex = lvwAutoLogins.SelectedIndices[0];
			if (lvwAutoLogins.Items.Count-1 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileAutoLogin tmp = working_i.autoLogin[iIndex+1];
			working_i.autoLogin[iIndex+1] = working_i.autoLogin[iIndex];
			working_i.autoLogin[iIndex] = tmp;
			
			PopulateAutoLoginList();
			
			lvwAutoLogins.Items[iIndex+1].Selected = true;	
		}
		
		void CmdAutoLoginNewClick(object sender, System.EventArgs e)
		{
			logsetLogfileAutoLogin autologin = new logsetLogfileAutoLogin();
			autologin.send = new logsetLogfileAutoLoginSend();
			
			AutoLoginForm f = new AutoLoginForm(autologin);
			f.ShowDialog();
			
			if (! f.WasCancelled)
			{
				logsetLogfileAutoLogin[] origArray = working_i.autoLogin;
				
				logsetLogfileAutoLogin[] newArray = new logsetLogfileAutoLogin[origArray.Length+1];
				
				for (int i=0; i<origArray.Length; i++)
				{
					newArray[i] = origArray[i];
				}
				     
				newArray[newArray.Length-1] = autologin;
				
				working_i.autoLogin = newArray;
			}
			
			PopulateAutoLoginList();
		}
		
		void CmdAutoLoginEditClick(object sender, System.EventArgs e)
		{
			if (0 == lvwAutoLogins.Items.Count  ||  0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			int iIndex = lvwAutoLogins.SelectedIndices[0];
			logsetLogfileAutoLogin autologin = working_i.autoLogin[iIndex];			
			
			AutoLoginForm f = new AutoLoginForm(autologin);
			f.ShowDialog();
			
			PopulateAutoLoginList();
		}
		
		
		void LvwAutoLoginsDoubleClick(object sender, System.EventArgs e)
		{
			CmdAutoLoginEditClick(sender, e);
		}
		
		
		void CmdAutoLoginDeleteClick(object sender, System.EventArgs e)
		{
			if (0 == lvwAutoLogins.Items.Count  ||  0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			int iIndex = lvwAutoLogins.SelectedIndices[0];
			logsetLogfileAutoLogin autologin = working_i.autoLogin[iIndex];
			
			if (DialogResult.Yes == MessageBox.Show ("Are you sure you want to remove this auto-login check?", this.Text, MessageBoxButtons.YesNo))
			{				
				logsetLogfileAutoLogin[] origArray = working_i.autoLogin;
					
				logsetLogfileAutoLogin[] newArray = new logsetLogfileAutoLogin[origArray.Length-1];
				
				for (int i=0; i<origArray.Length; i++)
				{					
					if (i < iIndex)
					{
						newArray[i] = origArray[i];
					}
					else if (i > iIndex)
					{
						newArray[i-1] = origArray[i];
					}
				}
								
				working_i.autoLogin = newArray;
				
				PopulateAutoLoginList();
			}
		}
		
		
		
		void CmdLocalBrowseClick(object sender, System.EventArgs e)
		{
			if (System.IO.File.Exists(txtLocalPath.Text))
			{
				openFileDialog1.FileName = txtLocalPath.Text;
			}
			
			openFileDialog1.Multiselect = false;
			if (DialogResult.OK == openFileDialog1.ShowDialog())
			{
				txtLocalPath.Text = openFileDialog1.FileName;
			}						
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(EditLogFile));
			this.picPassword = new System.Windows.Forms.PictureBox();
			this.txtTailCommand = new System.Windows.Forms.TextBox();
			this.grpTelnet = new System.Windows.Forms.GroupBox();
			this.txtUsername = new System.Windows.Forms.TextBox();
			this.cmdLocalBrowse = new System.Windows.Forms.Button();
			this.cmdAutoLoginDown = new System.Windows.Forms.Button();
			this.colWaitFor = new System.Windows.Forms.ColumnHeader();
			this.cmdImport = new System.Windows.Forms.Button();
			this.colMatch = new System.Windows.Forms.ColumnHeader();
			this.txtDisplayName = new System.Windows.Forms.TextBox();
			this.lblUsernameAndPassword = new System.Windows.Forms.Label();
			this.cmdMatchDown = new System.Windows.Forms.Button();
			this.txtTelnetPath = new System.Windows.Forms.TextBox();
			this.grpLocal = new System.Windows.Forms.GroupBox();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.cmdEditMatch = new System.Windows.Forms.Button();
			this.txtLocalPath = new System.Windows.Forms.TextBox();
			this.cmdAutoLoginEdit = new System.Windows.Forms.Button();
			this.colColour = new System.Windows.Forms.ColumnHeader();
			this.cmdDeleteMatch = new System.Windows.Forms.Button();
			this.lblPassword = new System.Windows.Forms.Label();
			this.colReplace = new System.Windows.Forms.ColumnHeader();
			this.cmdAutoLoginUp = new System.Windows.Forms.Button();
			this.lblUsername = new System.Windows.Forms.Label();
			this.lvwMatches = new System.Windows.Forms.ListView();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.cmdAutoLoginNew = new System.Windows.Forms.Button();
			this.colSend = new System.Windows.Forms.ColumnHeader();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.cmdAutoLoginDelete = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.txtHost = new System.Windows.Forms.TextBox();
			this.cmdCancel = new System.Windows.Forms.Button();
			this.lvwAutoLogins = new System.Windows.Forms.ListView();
			this.optSSH = new System.Windows.Forms.RadioButton();
			this.optLocal = new System.Windows.Forms.RadioButton();
			this.cmdMatchUp = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.cmdNewMatch = new System.Windows.Forms.Button();
			this.optTelnet = new System.Windows.Forms.RadioButton();
			this.cmdOK = new System.Windows.Forms.Button();
			this.label6 = new System.Windows.Forms.Label();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.grpTelnet.SuspendLayout();
			this.grpLocal.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// picPassword
			// 
			this.picPassword.Image = ((System.Drawing.Image)(resources.GetObject("picPassword.Image")));
			this.picPassword.Location = new System.Drawing.Point(248, 96);
			this.picPassword.Name = "picPassword";
			this.picPassword.Size = new System.Drawing.Size(24, 24);
			this.picPassword.TabIndex = 4;
			this.picPassword.TabStop = false;
			// 
			// txtTailCommand
			// 
			this.txtTailCommand.Location = new System.Drawing.Point(328, 64);
			this.txtTailCommand.Name = "txtTailCommand";
			this.txtTailCommand.Size = new System.Drawing.Size(128, 20);
			this.txtTailCommand.TabIndex = 1;
			this.txtTailCommand.Tag = "This is the command to run in order to \'tail\' the log file.  The path to the log " +
"file will be appended to this command when it is run.";
			this.txtTailCommand.Text = "";
			// 
			// grpTelnet
			// 
			this.grpTelnet.Controls.Add(this.picPassword);
			this.grpTelnet.Controls.Add(this.groupBox2);
			this.grpTelnet.Controls.Add(this.txtTelnetPath);
			this.grpTelnet.Controls.Add(this.label3);
			this.grpTelnet.Controls.Add(this.txtHost);
			this.grpTelnet.Controls.Add(this.label4);
			this.grpTelnet.Controls.Add(this.txtTailCommand);
			this.grpTelnet.Controls.Add(this.label5);
			this.grpTelnet.Controls.Add(this.lblUsername);
			this.grpTelnet.Controls.Add(this.txtUsername);
			this.grpTelnet.Controls.Add(this.lblPassword);
			this.grpTelnet.Controls.Add(this.lblUsernameAndPassword);
			this.grpTelnet.Location = new System.Drawing.Point(16, 88);
			this.grpTelnet.Name = "grpTelnet";
			this.grpTelnet.Size = new System.Drawing.Size(472, 312);
			this.grpTelnet.TabIndex = 3;
			this.grpTelnet.TabStop = false;
			this.grpTelnet.Text = "Telnet file details";
			this.grpTelnet.Enter += new System.EventHandler(this.GrpTelnetEnter);
			// 
			// txtUsername
			// 
			this.txtUsername.Location = new System.Drawing.Point(104, 96);
			this.txtUsername.Name = "txtUsername";
			this.txtUsername.Size = new System.Drawing.Size(128, 20);
			this.txtUsername.TabIndex = 1;
			this.txtUsername.Tag = "For SSH logins you can specify the username here.  You will be prompted for the p" +
"assword on startup.";
			this.txtUsername.Text = "";
			// 
			// cmdLocalBrowse
			// 
			this.cmdLocalBrowse.Location = new System.Drawing.Point(384, 40);
			this.cmdLocalBrowse.Name = "cmdLocalBrowse";
			this.cmdLocalBrowse.TabIndex = 2;
			this.cmdLocalBrowse.Tag = "Clicking this button will allow you to use the standard Windows \'open file\' box t" +
"o locate your log file.";
			this.cmdLocalBrowse.Text = "Browse...";
			this.cmdLocalBrowse.Click += new System.EventHandler(this.CmdLocalBrowseClick);
			// 
			// cmdAutoLoginDown
			// 
			this.cmdAutoLoginDown.Location = new System.Drawing.Point(72, 128);
			this.cmdAutoLoginDown.Name = "cmdAutoLoginDown";
			this.cmdAutoLoginDown.Size = new System.Drawing.Size(48, 23);
			this.cmdAutoLoginDown.TabIndex = 1;
			this.cmdAutoLoginDown.Tag = "Moves the currently selected \'auto login\' item downwards in the list.";
			this.cmdAutoLoginDown.Text = "Down";
			this.cmdAutoLoginDown.Click += new System.EventHandler(this.CmdAutoLoginDownClick);
			// 
			// colWaitFor
			// 
			this.colWaitFor.Text = "Wait for this";
			this.colWaitFor.Width = 200;
			// 
			// cmdImport
			// 
			this.cmdImport.Location = new System.Drawing.Point(520, 120);
			this.cmdImport.Name = "cmdImport";
			this.cmdImport.Size = new System.Drawing.Size(104, 23);
			this.cmdImport.TabIndex = 8;
			this.cmdImport.Text = "Import Settings...";
			this.cmdImport.Click += new System.EventHandler(this.CmdImportClick);
			// 
			// colMatch
			// 
			this.colMatch.Text = "Look for";
			this.colMatch.Width = 120;
			// 
			// txtDisplayName
			// 
			this.txtDisplayName.Location = new System.Drawing.Point(112, 24);
			this.txtDisplayName.Name = "txtDisplayName";
			this.txtDisplayName.Size = new System.Drawing.Size(256, 20);
			this.txtDisplayName.TabIndex = 1;
			this.txtDisplayName.Tag = "An arbitrary name for this log file, e.g. \"JBoss server log\"";
			this.txtDisplayName.Text = "";
			// 
			// lblUsernameAndPassword
			// 
			this.lblUsernameAndPassword.Location = new System.Drawing.Point(16, 96);
			this.lblUsernameAndPassword.Name = "lblUsernameAndPassword";
			this.lblUsernameAndPassword.Size = new System.Drawing.Size(432, 32);
			this.lblUsernameAndPassword.TabIndex = 0;
			this.lblUsernameAndPassword.Text = "Use the Auto Login feature below to automatically send username and password.";
			// 
			// cmdMatchDown
			// 
			this.cmdMatchDown.Location = new System.Drawing.Point(72, 128);
			this.cmdMatchDown.Name = "cmdMatchDown";
			this.cmdMatchDown.Size = new System.Drawing.Size(48, 23);
			this.cmdMatchDown.TabIndex = 1;
			this.cmdMatchDown.Tag = "Moves the selected replacement/highlight operation down in the list.";
			this.cmdMatchDown.Text = "Down";
			this.cmdMatchDown.Click += new System.EventHandler(this.CmdMatchDownClick);
			// 
			// txtTelnetPath
			// 
			this.txtTelnetPath.Location = new System.Drawing.Point(104, 32);
			this.txtTelnetPath.Name = "txtTelnetPath";
			this.txtTelnetPath.Size = new System.Drawing.Size(352, 20);
			this.txtTelnetPath.TabIndex = 1;
			this.txtTelnetPath.Tag = @"The path to the log file on the remote host.  You can include wildcard characters which will be interpreted by the host's shell (ksh, bash etc), or you can use date formatters %d, %m, %y which will be converted into today's date, e.g. '%d-%m-%y' will be converted into '28-02-2005'.";
			this.txtTelnetPath.Text = "";
			// 
			// grpLocal
			// 
			this.grpLocal.Controls.Add(this.cmdLocalBrowse);
			this.grpLocal.Controls.Add(this.txtLocalPath);
			this.grpLocal.Controls.Add(this.label2);
			this.grpLocal.Location = new System.Drawing.Point(16, 88);
			this.grpLocal.Name = "grpLocal";
			this.grpLocal.Size = new System.Drawing.Size(472, 304);
			this.grpLocal.TabIndex = 4;
			this.grpLocal.TabStop = false;
			this.grpLocal.Text = "Local Windows file details";
			// 
			// cmdEditMatch
			// 
			this.cmdEditMatch.Location = new System.Drawing.Point(304, 128);
			this.cmdEditMatch.Name = "cmdEditMatch";
			this.cmdEditMatch.TabIndex = 1;
			this.cmdEditMatch.Tag = "Allows you to edit the properties of the selected search/replace/highlight operat" +
"ion.";
			this.cmdEditMatch.Text = "Edit...";
			this.cmdEditMatch.Click += new System.EventHandler(this.CmdEditMatchClick);
			// 
			// txtLocalPath
			// 
			this.txtLocalPath.Location = new System.Drawing.Point(80, 40);
			this.txtLocalPath.Name = "txtLocalPath";
			this.txtLocalPath.Size = new System.Drawing.Size(304, 20);
			this.txtLocalPath.TabIndex = 1;
			this.txtLocalPath.Tag = "The absolute path to the log file.  You can use wildcards like * and ?, and you c" +
"an also use a combination of %d, %m and %y to represent the day, month and year " +
"respectively, e.g. \'%d-%m-%y\' would look for a file called \'25-12-2005\'.";
			this.txtLocalPath.Text = "";
			// 
			// cmdAutoLoginEdit
			// 
			this.cmdAutoLoginEdit.Location = new System.Drawing.Point(272, 128);
			this.cmdAutoLoginEdit.Name = "cmdAutoLoginEdit";
			this.cmdAutoLoginEdit.TabIndex = 1;
			this.cmdAutoLoginEdit.Tag = "Allows you to view and edit the currently selected \'auto login\' setting.";
			this.cmdAutoLoginEdit.Text = "Edit...";
			this.cmdAutoLoginEdit.Click += new System.EventHandler(this.CmdAutoLoginEditClick);
			// 
			// colColour
			// 
			this.colColour.Text = "Colour it in";
			this.colColour.Width = 100;
			// 
			// cmdDeleteMatch
			// 
			this.cmdDeleteMatch.Location = new System.Drawing.Point(384, 128);
			this.cmdDeleteMatch.Name = "cmdDeleteMatch";
			this.cmdDeleteMatch.TabIndex = 1;
			this.cmdDeleteMatch.Tag = "Allows you to delete the selected search/replace/highlight operation.";
			this.cmdDeleteMatch.Text = "&Delete";
			this.cmdDeleteMatch.Click += new System.EventHandler(this.CmdDeleteMatchClick);
			// 
			// lblPassword
			// 
			this.lblPassword.Location = new System.Drawing.Point(272, 96);
			this.lblPassword.Name = "lblPassword";
			this.lblPassword.Size = new System.Drawing.Size(192, 32);
			this.lblPassword.TabIndex = 0;
			this.lblPassword.Text = "You will be prompted for the password on startup.";
			// 
			// colReplace
			// 
			this.colReplace.Text = "Replace with this";
			this.colReplace.Width = 210;
			// 
			// cmdAutoLoginUp
			// 
			this.cmdAutoLoginUp.Location = new System.Drawing.Point(16, 128);
			this.cmdAutoLoginUp.Name = "cmdAutoLoginUp";
			this.cmdAutoLoginUp.Size = new System.Drawing.Size(48, 23);
			this.cmdAutoLoginUp.TabIndex = 1;
			this.cmdAutoLoginUp.Tag = "Moves the currently selected \'auto login\' item upwards in the list.";
			this.cmdAutoLoginUp.Text = "Up";
			this.cmdAutoLoginUp.Click += new System.EventHandler(this.CmdAutoLoginUpClick);
			// 
			// lblUsername
			// 
			this.lblUsername.Location = new System.Drawing.Point(16, 96);
			this.lblUsername.Name = "lblUsername";
			this.lblUsername.Size = new System.Drawing.Size(64, 16);
			this.lblUsername.TabIndex = 0;
			this.lblUsername.Text = "Username:";
			// 
			// lvwMatches
			// 
			this.lvwMatches.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
						this.colMatch,
						this.colReplace,
						this.colColour});
			this.lvwMatches.FullRowSelect = true;
			this.lvwMatches.HideSelection = false;
			this.lvwMatches.Location = new System.Drawing.Point(16, 24);
			this.lvwMatches.MultiSelect = false;
			this.lvwMatches.Name = "lvwMatches";
			this.lvwMatches.Size = new System.Drawing.Size(440, 97);
			this.lvwMatches.TabIndex = 0;
			this.lvwMatches.Tag = "A list of all the search/replace/highlight operations you want to do on this file" +
".  These allow you to remove certain lines, replace parts of lines, and colour t" +
"he lines in as the log file grows.";
			this.lvwMatches.View = System.Windows.Forms.View.Details;
			this.lvwMatches.DoubleClick += new System.EventHandler(this.LvwMatchesDoubleClick);
			this.lvwMatches.SelectedIndexChanged += new System.EventHandler(this.LvwMatchesSelectedIndexChanged);
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// cmdAutoLoginNew
			// 
			this.cmdAutoLoginNew.Location = new System.Drawing.Point(192, 128);
			this.cmdAutoLoginNew.Name = "cmdAutoLoginNew";
			this.cmdAutoLoginNew.TabIndex = 1;
			this.cmdAutoLoginNew.Tag = "Allows you to create a new auto login setting for this connection.";
			this.cmdAutoLoginNew.Text = "New...";
			this.cmdAutoLoginNew.Click += new System.EventHandler(this.CmdAutoLoginNewClick);
			// 
			// colSend
			// 
			this.colSend.Text = "Then send this text";
			this.colSend.Width = 200;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 64);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(168, 16);
			this.label4.TabIndex = 0;
			this.label4.Text = "Host name:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(248, 64);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 16);
			this.label5.TabIndex = 0;
			this.label5.Text = "Tail command:";
			// 
			// cmdAutoLoginDelete
			// 
			this.cmdAutoLoginDelete.Location = new System.Drawing.Point(352, 128);
			this.cmdAutoLoginDelete.Name = "cmdAutoLoginDelete";
			this.cmdAutoLoginDelete.TabIndex = 1;
			this.cmdAutoLoginDelete.Tag = "Deletes the currently selected \'auto login\' details.";
			this.cmdAutoLoginDelete.Text = "Delete";
			this.cmdAutoLoginDelete.Click += new System.EventHandler(this.CmdAutoLoginDeleteClick);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Display name:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 0;
			this.label2.Text = "File path:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 32);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(104, 24);
			this.label3.TabIndex = 0;
			this.label3.Text = "Path to file on remote machine:";
			// 
			// txtHost
			// 
			this.txtHost.Location = new System.Drawing.Point(104, 64);
			this.txtHost.Name = "txtHost";
			this.txtHost.Size = new System.Drawing.Size(128, 20);
			this.txtHost.TabIndex = 1;
			this.txtHost.Tag = "Enter the host name or IP address of the telnet host which contains the log files" +
".";
			this.txtHost.Text = "";
			// 
			// cmdCancel
			// 
			this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.cmdCancel.Location = new System.Drawing.Point(520, 48);
			this.cmdCancel.Name = "cmdCancel";
			this.cmdCancel.Size = new System.Drawing.Size(104, 23);
			this.cmdCancel.TabIndex = 6;
			this.cmdCancel.Tag = "Closes the dialog box, undoing any changes you have made.";
			this.cmdCancel.Text = "&Cancel";
			this.cmdCancel.Click += new System.EventHandler(this.CmdCancelClick);
			// 
			// lvwAutoLogins
			// 
			this.lvwAutoLogins.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
						this.colWaitFor,
						this.colSend});
			this.lvwAutoLogins.FullRowSelect = true;
			this.lvwAutoLogins.HideSelection = false;
			this.lvwAutoLogins.Location = new System.Drawing.Point(16, 24);
			this.lvwAutoLogins.MultiSelect = false;
			this.lvwAutoLogins.Name = "lvwAutoLogins";
			this.lvwAutoLogins.Size = new System.Drawing.Size(408, 96);
			this.lvwAutoLogins.SmallImageList = this.imageList1;
			this.lvwAutoLogins.TabIndex = 0;
			this.lvwAutoLogins.Tag = "Auto login allows you to wait for certain prompts to be echoed to the screen (e.g" +
". \'login\' and \'password\') and to send a given response when these prompts are de" +
"tected.";
			this.lvwAutoLogins.View = System.Windows.Forms.View.Details;
			this.lvwAutoLogins.DoubleClick += new System.EventHandler(this.LvwAutoLoginsDoubleClick);
			// 
			// optSSH
			// 
			this.optSSH.Location = new System.Drawing.Point(312, 56);
			this.optSSH.Name = "optSSH";
			this.optSSH.Size = new System.Drawing.Size(56, 16);
			this.optSSH.TabIndex = 1;
			this.optSSH.Tag = "Choose this option if you need to use telnet to access the log file (e.g. it resi" +
"des on a unix machine)";
			this.optSSH.Text = "SSH";
			this.optSSH.CheckedChanged += new System.EventHandler(this.OptSSHCheckedChanged);
			// 
			// optLocal
			// 
			this.optLocal.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.optLocal.Location = new System.Drawing.Point(112, 56);
			this.optLocal.Name = "optLocal";
			this.optLocal.Size = new System.Drawing.Size(120, 16);
			this.optLocal.TabIndex = 1;
			this.optLocal.Tag = "Choose this option if the log file you want to view resides on your local machine" +
" or on a Windows network.";
			this.optLocal.Text = "Local Windows file";
			this.optLocal.CheckedChanged += new System.EventHandler(this.OptLocalCheckedChanged);
			// 
			// cmdMatchUp
			// 
			this.cmdMatchUp.Location = new System.Drawing.Point(16, 128);
			this.cmdMatchUp.Name = "cmdMatchUp";
			this.cmdMatchUp.Size = new System.Drawing.Size(48, 23);
			this.cmdMatchUp.TabIndex = 1;
			this.cmdMatchUp.Tag = "Moves the selected replacement/highlight operation up in the list.";
			this.cmdMatchUp.Text = "Up";
			this.cmdMatchUp.Click += new System.EventHandler(this.CmdMatchUpClick);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.cmdDeleteMatch);
			this.groupBox1.Controls.Add(this.lvwMatches);
			this.groupBox1.Controls.Add(this.cmdEditMatch);
			this.groupBox1.Controls.Add(this.cmdNewMatch);
			this.groupBox1.Controls.Add(this.cmdMatchUp);
			this.groupBox1.Controls.Add(this.cmdMatchDown);
			this.groupBox1.Location = new System.Drawing.Point(16, 408);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(472, 168);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Replacements/highlighting";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.cmdAutoLoginDelete);
			this.groupBox2.Controls.Add(this.lvwAutoLogins);
			this.groupBox2.Controls.Add(this.cmdAutoLoginEdit);
			this.groupBox2.Controls.Add(this.cmdAutoLoginNew);
			this.groupBox2.Controls.Add(this.cmdAutoLoginDown);
			this.groupBox2.Controls.Add(this.cmdAutoLoginUp);
			this.groupBox2.Location = new System.Drawing.Point(16, 136);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(440, 168);
			this.groupBox2.TabIndex = 3;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Auto login commands";
			// 
			// cmdNewMatch
			// 
			this.cmdNewMatch.Location = new System.Drawing.Point(224, 128);
			this.cmdNewMatch.Name = "cmdNewMatch";
			this.cmdNewMatch.TabIndex = 1;
			this.cmdNewMatch.Tag = "Creates a new search/replace/highlight operation.";
			this.cmdNewMatch.Text = "&New...";
			this.cmdNewMatch.Click += new System.EventHandler(this.CmdNewMatchClick);
			// 
			// optTelnet
			// 
			this.optTelnet.Location = new System.Drawing.Point(240, 56);
			this.optTelnet.Name = "optTelnet";
			this.optTelnet.Size = new System.Drawing.Size(64, 16);
			this.optTelnet.TabIndex = 1;
			this.optTelnet.Tag = "Choose this option if you need to use telnet to access the log file (e.g. it resi" +
"des on a unix machine)";
			this.optTelnet.Text = "Telnet";
			this.optTelnet.CheckedChanged += new System.EventHandler(this.OptTelnetCheckedChanged);
			// 
			// cmdOK
			// 
			this.cmdOK.Location = new System.Drawing.Point(520, 16);
			this.cmdOK.Name = "cmdOK";
			this.cmdOK.Size = new System.Drawing.Size(104, 23);
			this.cmdOK.TabIndex = 5;
			this.cmdOK.Tag = "Closes the dialog box and temporarily saves any changes you have made.";
			this.cmdOK.Text = "&OK";
			this.cmdOK.Click += new System.EventHandler(this.CmdOKClick);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(16, 56);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(96, 24);
			this.label6.TabIndex = 0;
			this.label6.Text = "Connection type:";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.txtDisplayName);
			this.groupBox3.Controls.Add(this.grpLocal);
			this.groupBox3.Controls.Add(this.groupBox1);
			this.groupBox3.Controls.Add(this.grpTelnet);
			this.groupBox3.Controls.Add(this.optLocal);
			this.groupBox3.Controls.Add(this.label1);
			this.groupBox3.Controls.Add(this.optTelnet);
			this.groupBox3.Controls.Add(this.optSSH);
			this.groupBox3.Controls.Add(this.label6);
			this.groupBox3.Location = new System.Drawing.Point(8, 8);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(504, 592);
			this.groupBox3.TabIndex = 7;
			this.groupBox3.TabStop = false;
			// 
			// EditLogFile
			// 
			this.AcceptButton = this.cmdOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.cmdCancel;
			this.ClientSize = new System.Drawing.Size(634, 598);
			this.Controls.Add(this.cmdImport);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.cmdCancel);
			this.Controls.Add(this.cmdOK);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "EditLogFile";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Edit Log File";
			this.grpTelnet.ResumeLayout(false);
			this.grpLocal.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);
		}
		#endregion
		
		
		void CmdImportClick(object sender, System.EventArgs e)
		{
			ImportLogFileForm f = new ImportLogFileForm();
			f.ShowDialog();
			
			if (null != f.LogFile)
			{
				this.working_i = LogsetLoader.CloneLogfile(f.LogFile);
				PopulateFields();	
			}
		}
		
	}
}
